<template>
  <div>
<h2>投资列表显示</h2>
投资名称:<input type="text" v-model="showData.name">
投资总金额:<input type="text" v-model="showData.maxmoney">-
<input type="text" v-model="showData.minmoney">
<input type="button" value="查询" @click="getData">
<table>
  <tr>
    <td>投资名称</td>
    <td>投资总额度</td>
    <td>已投资额度</td>
    <td>剩余额度</td>
    <td>投资人数</td>
    <td>操作</td>
  </tr>
  <tr v-for="item in list" :key="item.I_Id">
    <td>{{ item.I_Name }}</td>
    <td>{{ item.I_Total }}</td>
    <td>{{ item.I_Money }}</td>
    <td>{{ item.I_Smoney }}</td>
    <td>{{ item.I_Num }}</td>
    <td>
      <input type="button" value="删除" @click="del(item.I_Id)">
      <input type="button" value="修改" @click="upt(item.I_Id)">
    </td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">

import {reactive,toRefs,onMounted} from 'vue'
import {useRouter} from 'vue-router'
import axios from 'axios'
const router = useRouter()

let data:any=reactive({
  list:[],
  showData:{
    name:'',
    maxmoney:'',
    minmoney:''
  }
})

let {list,showData} =toRefs(data)

onMounted(()=>{
  getData()
})

//显示查询
const getData=()=>{
  axios({
    url:'http://localhost:50805/api/Invest/GetShowInvest',
    method:'get',
    params:{
      name:showData.value.name,
      maxmoney:showData.value.maxmoney,
      minmoney:showData.value.minmoney
    }
  }).then(res=>{
    console.log(res)
    list.value=res.data.data
  }).catch(err=>{
    console.log(err)
  })
}

//删除
const del=(Iid:any)=>{
  if(!confirm("确定要删除吗？")){
    return
  }
  axios({
    url:'http://localhost:50805/api/Invest/GetDelInvest',
    method:'get',
    params:{
      Iid:Iid
    }
  }).then(res=>{
    console.log(res)
    if(res.data.data>0){
      alert("删除成功")
      getData()
    }else{
      alert("删除失败")
      getData()
    }
  }).catch(err=>{
    console.log(err)
  })
}


const upt=(Iid:any)=>{
  router.push({
    path:'/upt',
    query:{
      Iid:Iid
    }
  })
}




</script>

<style scoped>

</style>